import React from 'react';
import { useModel } from 'umi';
interface PermissionControlProps {
  action_id?: string;
}
const Index: React.FC<PermissionControlProps> = (props) => {
  const { initialState } = useModel('@@initialState');
  const buttonIdList = initialState?.buttonIdList || [];
  const { action_id } = props;
  const ids = action_id?.split(',') || [];
  let hasPermission = false;
  for (let i = 0; i < ids.length; i++) {
    if (buttonIdList.some(id => id === ids[i])) {
      hasPermission = true;
    }
  }

  if (!action_id) {
    hasPermission = true;
  }
  return (
    hasPermission ? <div className="permission-wrap" style={{display: 'inline-block'}}>{props.children}</div> : null
  );
};
export default Index;
